package com.note.tool;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class Mixup extends Thread {
    static int count = 0;

    public void run() {
        System.out.println(" Got "+ FF.bit + " begin folder : \n"+ FF.begin);
        String str = FF.begin;
        String[] ss = str.split("\\\\");
        FF.bit = ss[ss.length - 1];
        str = ss[ss.length - 2];
        String prestr = str.substring(0, 2);
        str = str.substring(2, str.length());
        int n = Integer.parseInt(str);
        System.out.println(" Got "+ FF.bit + " end folder :\n"+ FF.end);
        str = FF.end;
        ss = str.split("\\\\");
        FF.bit = ss[ss.length - 1];
        str = ss[ss.length - 2];
        str = str.substring(2, str.length());
        int m = Integer.parseInt(str);
        System.out.println(" Got bat folder : \n"+ FF.bat);
                String string = FF.bat;
        for (int i = n; i <= m; i++) {
            StringBuilder sb = new StringBuilder();
            for (int j = 0; j < ss.length; j++) {
                if (j == ss.length - 2) {
                    sb.append(prestr);
                    sb.append(String.valueOf(i));
                    sb.append("\\");
                } else {
                    sb.append(ss[j]);
                    sb.append("\\");
                }
            }
            System.out.println("traversal parsing : "+ i);
                    str = String.valueOf(sb);
            File f = new File(str);
            if (f.exists()) {
                System.out.println(" Have found : \n"+ f);
                        count++;
                File ff = new File(string, "Video.bat");
                File file = null;
                try {
                    file = new File(str, "Video.bat");
                    if (!file.exists())
                        file.createNewFile();
                    System.out.println(" Create empty : \n"+ file);
                            FileInputStream fis = new FileInputStream(ff);
                    FileOutputStream fos = new FileOutputStream(file);
                    byte[] bytes = new byte[1024];
                    int b = 0;
                    while ((b = fis.read(bytes)) != -1)
                        fos.write(bytes, 0, b);
                    fos.close();
                    fis.close();
                    System.out.println(" Have copied .bat");
                } catch (IOException e) {
                    e.printStackTrace();
                }
                String strcmd = "cmd /c  start  " + file;
                Cmd.run_cmd(strcmd);
            }
        }
        System.out.println("- Dirs count : " + (m - n + 1) + " parsing done ,\n- Waitting for " + count + " concat missions\n");
                count = 0;
    }
}
